package com.yykj.pay.server.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yykj.pay.server.entity.Order;
import com.yykj.pay.server.exception.ErrorCode;
import com.yykj.pay.server.exception.ErrorCodeException;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface OrderMapper extends BaseMapper<Order> {


    default Order findByOrderNo(String orderNo){
        LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
        orderLambdaQueryWrapper.eq(Order::getOrderNo, orderNo);
        Order order = this.selectOne(orderLambdaQueryWrapper);
        if(order == null){
            throw new ErrorCodeException(ErrorCode._9013);
        }
        return order;
    }
}
